<%--                                                                       --%>
<%-- Copyright (c) 2003-2005 BroadVision, Inc.  All rights reserved.       --%>
<%--                                                                       --%>
<%-- This software is copyrighted. Under the copyright laws, this software --%>
<%-- may not be copied, in whole or in part, without prior written consent --%>
<%-- of BroadVision, Inc. or its assignees. This software is provided      --%>
<%-- under the terms of a license between BroadVision and the recipient,   --%>
<%-- and its use is subject to the terms of that license.                  --%>
<%--                                                                       --%>
<%-- This software may be protected by one or more U.S. and International  --%>
<%-- patents.  Certain applications of BroadVision One-To-One software are --%>
<%-- covered by U.S. patent 5,710,887.                                     --%>
<%--                                                                       --%>
<%-- TRADEMARKS: BroadVision and BroadVision One-To-One are registered     --%>
<%-- trademarks of BroadVision, Inc., in the United States and the         --%>
<%-- European Community, and are trademarks of BroadVision, Inc., in other --%>
<%-- countries.  The BroadVision logo, is a trademark of BroadVision,      --%>
<%-- Inc., in the United States and other countries. Additionally, IONA    --%>
<%-- and Orbix are trademarks of IONA Technologies, Ltd.  RSA, MD5, and    --%>
<%-- RC2 are trademarks of RSA Data Security, Inc.                         --%>
<%--                                                                       --%>

<%@ page import =  "com.broadvision.web.util.ViewDynaBean,
                    java.util.HashMap,
		    org.apache.commons.beanutils.PropertyUtils"
%>

<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>

<script language="javascript" src="<%=request.getContextPath()%>/mc/js/date.js">
</script>

<script language="JavaScript">

  function check(field, button) {
    var SelectAllTxt = '<bean:message key="button.selectAll" bundle="bp.messages"/>';
    var UnselectAllTxt = '<bean:message key="button.unselectAll" bundle="bp.messages"/>';
    if (field == null) {
      button.value = SelectAllTxt;
    }
    var checkflag = "false";
    if (button.value == SelectAllTxt) {
      checkflag = "false";
    }
    if (button.value == UnselectAllTxt) {
      checkflag = "true";
    }
    var max = field.length;
    if (max > 1) {
      if (checkflag == "false") {
        for (i = 0; i < max; i++) {
          field[i].checked = true;
        }
        button.value = UnselectAllTxt;
      } else {
        for (i = 0; i < max; i++) {
          field[i].checked = false;
        }
        button.value = SelectAllTxt;
      }
    } else {
      if (checkflag == "false") {
        field.checked = true;
        button.value = UnselectAllTxt;
      } else {
        field.checked = false;
        button.value = SelectAllTxt;
      }
    }
  }
  
  function updateCheckbox(field, button) {
    var SelectAllTxt = '<bean:message key="button.selectAll" bundle="bp.messages"/>';
    var UnselectAllTxt = '<bean:message key="button.unselectAll" bundle="bp.messages"/>';
    if (field == null) {
      button.value = SelectAllTxt;
    }
    var checkflag = "false";
    if (button.value == SelectAllTxt) {
      checkflag = "false";
    }
    if (button.value == UnselectAllTxt) {
      checkflag = "true";
    }
    var max = field.length;
    if (max > 1) {
      if (checkflag == "false") {
        for (i = 0; i < max; i++) {
          if (field[i].checked == false) {
            return;
          }
        }
        button.value = UnselectAllTxt;
      } else {
        for (i = 0; i < max; i++) {
          if (field[i].checked == true) {
            return;
          }
        }
        button.value = SelectAllTxt;
      }
    } else {
      if (checkflag == "false") {
        if (field.checked == true) {
          button.value = UnselectAllTxt;
        }
      } else {
        if (field.checked == false) {
          button.value = SelectAllTxt;
        }
      }
    }
  }

  function isAnyChecked(field, alertmsg, confirmmsg) {
    if (field == null) {
      if (alertmsg != null && alertmsg.length > 0) {
        alert(alertmsg);
      }
      return false;
    }
    else if (field.length == null) {
      if (field.checked == false) {
        if (alertmsg != null && alertmsg.length > 0) {
          alert(alertmsg);
        }
        return false;
      }
      else {
        if (confirmmsg != null && confirmmsg.length > 0) {
          return confirm(confirmmsg);
        }
        else {
          return true;
        }
      }
    }
    else {
      for (var j = 0; j < field.length; j++) {
        if (field[j].checked) {
          if (confirmmsg != null && confirmmsg.length > 0) {
            return confirm(confirmmsg);
          }
          else {
            return true;
          }
        }
      }
      if (alertmsg != null && alertmsg.length > 0) {
        alert(alertmsg);
      }
      return false;
    }
  }

  function doReassignTasksToAction(theForm) {
    theForm.action = '<html:rewrite page="/bp/reassignTasksTo.do"/>';
    theForm.submit();
    return false;
  }
  
</script>

<% 
  java.util.HashMap map = new java.util.HashMap();
  String userId = request.getParameter("userId"); 

  map.put("userId", userId);

  pageContext.setAttribute("pagetabParam", map, PageContext.PAGE_SCOPE);
%>


<html:form action="/bp/reassignTasksTo.do" >

<% 
   ViewDynaBean userTaskListView = (ViewDynaBean) request.getAttribute("userTaskListView");
   String userNameFromView = (String) PropertyUtils.getSimpleProperty(userTaskListView, "fullName");

%>

<html:hidden property="userId" />
<html:hidden property="userNameFrom" value="<%= userNameFromView %>"/>
<html:hidden property="formAction" value="to"/>
<html:hidden property="origin" value="taskList"/>
<html:hidden property="firstNameTo" />
<html:hidden property="lastNameTo" />
<html:hidden property="fullNameTo" />
<html:hidden property="userAliasTo" />

<table class="zoneFive" width="100%" border="0" cellspacing="0" cellpadding="0" summary="content area">
  <tr>
    <td valign="top" width="100%">
      <div class="pageTitle">
        <bean:write name="userTaskListView" property="fullName"/>
      </div> 

      <!-- pageTab -->
      <div class="errorMessage"><html:errors bundle="bp.messages"/></div>
      <%@include file="/mc/common/pagetab.jsp" %>

      <bean:size id="taskCount" name="userTaskListView" property="userTaskList"/>
      <logic:equal name="taskCount" value="0">

        <div class="pageSubtitle">
          <span class="left">
            <bean:message key="bp.user.userTaskListBody.pageSubtitle" bundle="bp.messages"/>
          </span>
          <span class="right">&nbsp;</span>
        </div> 

        <!--end page title area here-->

        <table class="dataTable" border="0" cellspacing="1" cellpadding="2" summary="<bean:message key="bp.user.resultSummary" bundle="bp.messages"/>" width="100%">
          <tr class="listHeader">
              <th id="TaskName" align="left"><bean:message key="bp.user.reassignTasks.name"  bundle="bp.messages"/></th>
              <th id="ProcessId" align="left"><bean:message key="bp.user.reassignTasks.processInstanceId"  bundle="bp.messages"/></th>
              <th id="Priority" align="left"><bean:message key="bp.user.reassignTasks.priority"  bundle="bp.messages"/></th>
              <th id="DueDate" align="left"><bean:message key="bp.user.reassignTasks.dueDate"  bundle="bp.messages"/></th>
          </tr>
          <tr class="listEven">
            <td align="center" colspan="4">
               <bean:message key="bp.user.reassignTasks.noTask"  bundle="bp.messages"/>
            </td>
          </tr>
        </table>         
      </logic:equal>

      <logic:notEqual name="taskCount" value="0">

        <div class="pageSubtitle">
          <span class="left">
            <bean:message key="bp.user.userTaskListBody.pageSubtitle" bundle="bp.messages"/>&nbsp;-
            <bean:write name="taskCount"/>
            <bean:message key="bp.user.userTaskListBody.pageSubtitle.assignedTasks" bundle="bp.messages"/>
          </span>
          <span class="right">&nbsp;</span>
        </div> 

        <!--end page title area here-->

        <logic:equal name="userTaskListView" property="canEdit" value="true">

          <div class="globalButtonWrap">
            <input type="button" name="selectAllTasks" class="globalButton" onclick="check(this.form.taskIds, this);" value='<bean:message key="button.selectAll" bundle="bp.messages"/>'>
          </div>
			
<!-- Start List here -->

          <table class="dataTable" border="0" cellspacing="1" cellpadding="2" summary="<bean:message key="bp.user.resultSummary" bundle="bp.messages"/>" width="100%">
            <tr class="listHeader">
              <th id="Checkboxes" align="center">&nbsp;</th> 
              <th id="TaskName" align="left"><bean:message key="bp.user.reassignTasks.name"  bundle="bp.messages"/></th>
              <th id="ProcessId" align="left"><bean:message key="bp.user.reassignTasks.processInstanceId"  bundle="bp.messages"/></th>
              <th id="Priority" align="left"><bean:message key="bp.user.reassignTasks.priority"  bundle="bp.messages"/></th>
              <th id="DueDate" align="left"><bean:message key="bp.user.reassignTasks.dueDate"  bundle="bp.messages"/></th>
            </tr>
 
            <logic:iterate id="task" name="userTaskListView" property="userTaskList" indexId="i">

            <tr class="<%=i.intValue() % 2 == 0 ? "listEven" : "listOdd" %>">

              <td id="Checkboxes" align="center">
                <html:multibox property="taskIds" onclick="updateCheckbox(this.form.taskIds, this.form.selectAllTasks);" >
                  <bean:write name="task" property="taskId"/>
                </html:multibox>                  
              </td> 
              <td headers="TaskName" align="left">
                 <bean:write name="task" property="taskName"/>
              </td>
              <td headers="ProcessId" align="left">
                 <bean:write name="task" property="processInstanceId"/>
              </td>
              <td headers="Priority" align="left">
                 <bean:write name="task" property="priority"/>
              </td>
              <td headers="DueDate" align="left">
                <bean:write name="task" property="dueDate" formatKey="format.datetime.long" bundle="mc.messages"/>
              </td>
            </tr>
            </logic:iterate>
          </table>

          <div class="pageButtonWrap" align="right">

            <input type="button" name="nextBtn" class="globalButton"
onclick="if (isAnyChecked(this.form.taskIds, '<bean:message
key="bp.user.reassignTasks.alert.atLeastOne" bundle="bp.messages"/>', '')) return doReassignTasksToAction(this.form);" value='<bean:message key="button.reassign" bundle="bp.messages"/>'>

          </div>
        </logic:equal>

<!-- do not have the right to edit -->

        <logic:notEqual name="userTaskListView" property="canEdit" value="true">
			
<!-- Start List here -->

          <table class="dataTable" border="0" cellspacing="1" cellpadding="2" summary="<bean:message key="bp.user.resultSummary" bundle="bp.messages"/>" width="100%">
            <tr class="listHeader">
              <th id="TaskName" align="left"><bean:message key="bp.user.reassignTasks.name"  bundle="bp.messages"/></th>
              <th id="ProcessId" align="left"><bean:message key="bp.user.reassignTasks.processInstanceId"  bundle="bp.messages"/></th>
              <th id="Priority" align="left"><bean:message key="bp.user.reassignTasks.priority"  bundle="bp.messages"/></th>
              <th id="DueDate" align="left"><bean:message key="bp.user.reassignTasks.dueDate"  bundle="bp.messages"/></th>
            </tr>

            <logic:iterate id="task" name="userTaskListView" property="userTaskList" indexId="i">

            <tr class="<%=i.intValue() % 2 == 0 ? "listEven" : "listOdd" %>">
              <td headers="TaskName" align="left">
                 <bean:write name="task" property="taskName"/>
              </td>
              <td headers="ProcessId" align="left">
                 <bean:write name="task" property="processInstanceId"/>
              </td>
              <td headers="Priority" align="left">
                 <bean:write name="task" property="priority"/>
              </td>
              <td headers="DueDate" align="left">
                <bean:write name="task" property="dueDate" formatKey="format.datetime.tasklist" bundle="mc.messages"/>
              </td>
            </tr>
            </logic:iterate>
          </table>
        </logic:notEqual>
      </logic:notEqual>
      <!--end list here-->
    </td>
  </tr>
</table>

</html:form>

<!--end zone 5 content here -->

